#!/usr/bin/python
# -*- coding: UTF-8 -*-

from Recorder import recorder as rd
from SpeechRecognition import speechRecognition as sR
from RobotInteraction import robotInteraction as rI
from SpeechSynthesis import speechSynthesis as sS


"""
function: 接收用户语音,存储为wav音频文件
"""
def get_UserAudio():
    rd.recording()


"""
function: 将音频文件转成文字信息
return: 转化成功后的文字信息
"""
def audio_word():
    filename = "say_voice.wav"
    userInfo = sR.speechRecognition(filename)
    return userInfo


"""
function: 接收用户对话,返回相应对话
parameter: userInfo 用户描述的言语
return: 反馈用户的交互文字信息
"""
def getInteractiveInfo(userInfo):
    feedbackInfo = rI.get_response(userInfo)
    return feedbackInfo


"""
function: 接收用户语音,转成文字
return: 用户的言语文字
"""
def AcceptDialogue():
    phrase = speech.input()
    return phrase.encode('gb2312')


"""
function: 接收文字,转成语音播出
parameter: 反馈用户的言语
"""
def speechSyn(feedbackInfo):
    sS.synthesisInfo(feedbackInfo)
    sS.voiceBroadcast('hello.wav')


"""
function: 借用高级接口实现语音聊天
"""
def main():
    while True:
        get_UserAudio()
        userInfo = audio_word()
        print(userInfo)
        feedbackInfo = getInteractiveInfo(userInfo)
        print(feedbackInfo)
        speechSyn(feedbackInfo)


main()
